# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)

project("zbar")

add_subdirectory(ohoslog)

project(libiconv)

set(CMAKE_VERBOSE_MAKEFILE on)

set(libiconv_DIR ${CMAKE_SOURCE_DIR}/libiconv-1.15)

message("libiconv_DIR: ${libiconv_DIR}")
message("libiconv_DIR: ${libiconv_DIR}/lib/iconv.c")

add_compile_options(
    -Wno-multichar
    -D_ANDROID
    -DLIBDIR="c"
    -DBUILDING_LIBICONV
    -DBUILDING_LIBCHARSET
    -DIN_LIBRARY)

file(GLOB libiconv_SRC
    ${libiconv_DIR}/lib/iconv.c
    ${libiconv_DIR}/libcharset/lib/localcharset.c
    ${libiconv_DIR}/lib/relocatable.c)

add_library(iconv SHARED
    ${libiconv_SRC})

target_include_directories(iconv PRIVATE
    ${libiconv_DIR}/include
    ${libiconv_DIR}/libcharset
    ${libiconv_DIR}/libcharset/include
)

project(zbarjni)

file(GLOB zbarjni_SRC
    zbarjni.c
    zbar/img_scanner.c
    zbar/decoder.c
    zbar/image.c
    zbar/symbol.c
    zbar/convert.c
    zbar/config.c
    zbar/scanner.c
    zbar/error.c
    zbar/refcnt.c
    zbar/video.c
    zbar/video/null.c
    zbar/decoder/code128.c
    zbar/decoder/code39.c
    zbar/decoder/code93.c
    zbar/decoder/codabar.c
    zbar/decoder/databar.c
    zbar/decoder/ean.c
    zbar/decoder/i25.c
    zbar/decoder/qr_finder.c
    zbar/qrcode/bch15_5.c
    zbar/qrcode/binarize.c
    zbar/qrcode/isaac.c
    zbar/qrcode/qrdec.c
    zbar/qrcode/qrdectxt.c
    zbar/qrcode/rs.c
    zbar/qrcode/util.c)

add_library(zbarjni SHARED
    ${zbarjni_SRC})

target_include_directories(zbarjni PRIVATE
    .
    include
    zbar
    ${libiconv_DIR}/include)

target_link_libraries(zbarjni iconv ohoslog hilog_ndk.z)